<?php
class Course
{
    private $code;       
    private $name;        
    private $instructor;  
    private $credits;     
    private $students = []; 

    function __construct($code, $name, $instructor, $credits)
    {
        $this->code = $code;
        $this->name = $name;
        $this->instructor = $instructor;
        $this->credits = $credits;
    }

    function add_student($student)
    {
        if ($student instanceof Student) {
            $this->students[] = $student;
        }
    }

    function get_student_count()
    {
        return count($this->students);
    }

function toString()
{
    $result = "Course: {$this->code} - {$this->name}\n";
    $result .= "Instructor: {$this->instructor}\n";
    $result .= "Credits: {$this->credits}\n";
    $result .= "Enrolled students ({$this->get_student_count()}):\n";
    
    foreach ($this->students as $index => $student) {
        $result .= "  " . ($index + 1) . ". " 
                . $student->get_first_name() . " "  
                . $student->get_surname() .         
                " (Avg: " . $student->average() . ")\n";
    }
    
    return '<pre>' . $result . '</pre>';
}
}
?>
    